package com.common.basis.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 网络工具类
 *
 * @author mengchao
 * @date 2021/11/13
 */
public class NetToolUtils {
    public static String getIp() {
        InetAddress addr;
        try {
            addr = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            return null;
        }
        return addr.getHostAddress();
    }

    public static String getLoginSourceByRequestHeader(String info) {
        try {
            if (info.contains("web-pc")) {
                return StringMappingTool.WEB_PC;
            }

            if (info.contains("xcx")) {
                return StringMappingTool.APPLETS;
            }
            return StringMappingTool.UNKNOWN;
        } catch (Exception e) {
            return StringMappingTool.UNKNOWN;
        }
    }
}
